package com.hcms.system.service.impl;

import com.hcms.common.utils.tree.TreeUtil;
import com.hcms.system.dao.RoleDao;
import com.hcms.system.domain.RoleDo;
import com.hcms.system.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.*;

@Service
public class RoleServiceImpl implements RoleService {

    @Autowired
    RoleDao roleMapper;

    @Override
    public RoleDo get(int id) {
        RoleDo roleDo = roleMapper.get(id);
        return roleDo;
    }

    @Override
    public List<RoleDo> list(Map<String, Object> map) {
        List<RoleDo> roles = roleMapper.list(map);
        return roles;
    }

    @Override
    public int count(Map<String, Object> map) {
        int count = roleMapper.count(map);
        return count;
    }

    @Override
    public int save(RoleDo role) {
        Date date = new Date();
        role.setCreateTime(date);
        role.setUpdateTime(date);
        int count = roleMapper.save(role);
        return count;
    }

    @Override
    public int update(RoleDo role) {
        role.setUpdateTime(new Date());
        int count = roleMapper.update(role);
        return count;
    }

    @Override
    public List<RoleDo> tree() {
        List<RoleDo> roles = roleMapper.list(new HashMap<>());
        return new TreeUtil().getTree(roles);
    }
}
